package com.example.controller;


import com.example.anno.Log;
import com.example.pojo.Dept;
import com.example.pojo.Result;
import com.example.service.impl.DataServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.PanelUI;
import java.util.List;
@Slf4j
@RequestMapping("/depts")
@RestController
public class DataController {
//查询全部部门
    @Autowired
    private DataServiceImpl dataService;
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
// 请求为指定方式为GET
    @GetMapping
     public Result list(){
        log.info("查询全部部门");
        List<Dept> deptList = dataService.findAll();
        return Result.success(deptList);
     }
     //删除部门
    @Log
    @DeleteMapping
    public Result delete(Integer id){
        log.info("删除部门的序号:{}",id);
        dataService.delete(id);
    return Result.success(id);
    }

    //添加部门
    @Log
    @PostMapping
    public Result and(@RequestBody Dept dept){
        log.info("添加部门的序号:{}",dept);
        dataService.add(dept);
        return Result.success();
    }
    //查询部门
    @GetMapping("/{id}")
    public Result update(@PathVariable("id") Integer id){
        log.info("查询部门的序号:{}",id);
        Dept dept = dataService.select(id);
        return  Result.success(dept);
    }
    //修改部门
    @Log
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门的序号:{}",dept);
        dataService.update(dept);
       return Result.success();
    }
}
